package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.Product;
import service.impl.ProductManagerFactory;
import service.impl.WarehouseManagerFactory;
import service.impl.WarehouseManagerImpl;

/**
 * Servlet implementation class ListUpdateServlet
 */
@WebServlet("/sec/listupdate")
public class ProductListUpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ProductListUpdateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		String wid = request.getParameter("wid");
		String curWid = (String) request.getAttribute("curw");
		
		if(wid==null||wid.trim().length()==0){
			if(curWid!=null)
			wid = curWid;
		}
		
		List<Product> list = ProductManagerFactory.getInstance().findAllProduct(wid);
		for(Product it :list){
			System.out.println(it);
		}
		
		request.setAttribute("curw", wid);
		request.setAttribute("plist", list);

		request.getRequestDispatcher("warehouse.jsp").forward(request, response);
	}

}
